package com.zyc.fuckfx.base;

import com.zyc.fuckfx.FuckApplication;
import javafx.scene.image.Image;

import java.io.File;
import java.net.MalformedURLException;

/**
 * @Author AlbertZyc
 * @Date 2022/8/14
 * @description 自己悟出来
 */
public class ImageUtils {
    /**
     * 文件必须在mipmap目录下
     */
    public static Image getResImage(String imgName) {
        return new Image(FuckApplication.class.getResourceAsStream("/mipmap/" + imgName));
    }

    public static Image getFileImage(String path) throws MalformedURLException {
        try {
            File file = new File(path);
            String localFile = file.toURI().toURL().toString();
            return new Image(localFile);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
